package com.thd.springboottest.neo4j.dao;

import com.thd.springboottest.neo4j.pojo.CompanyGraph;
import com.thd.springboottest.neo4j.pojo.SupplyGraph;
import com.thd.springboottest.neo4j.pojo.SupplyRelationship;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class NeoService {
    @Resource
    private SupplyGraphRepository supplyGraphRepository;

    @Resource
    private CompanyGraphRepository companyGraphRepository;

    @Resource
    private SupplyRelationshipRepository supplyRelationshipRepository;

    public void testSave() {
        // supply
        String scale = "48%";
        String amount = "180000";
        String supplyName = "供应商-A";
        String companyName = "公司-C";
        String indexName = "SUPPLY 关系";
        // 构建supplyGraph
        SupplyGraph supplyGraph = SupplyGraph.builder().name(supplyName).build();
        // 保存操作
        supplyGraphRepository.save(supplyGraph);
        // company
        CompanyGraph companyGraph = CompanyGraph.builder().name(companyName).build();
        companyGraphRepository.save(companyGraph);
        // relation
        SupplyRelationship supplyRelationship = SupplyRelationship.builder()
                .indexName(indexName).amount(amount).scale(scale)
                .company(companyGraph).supply(supplyGraph).build();
        supplyRelationshipRepository.save(supplyRelationship);
        System.out.println("全部完成");
    }
}
